package com.sunwayworld.dev.util;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.Statement;

public class ConnUtil {

	public static Connection getConnection() {

		String className = DevConfigUtil.getProperty("connection_driver");
		String url = DevConfigUtil.getProperty("connection_url");
		String userName = DevConfigUtil.getProperty("connection_username");
		String passWord = DevConfigUtil.getProperty("connection_password");
		Connection conn = null;
		try {
			Class.forName(className);
			conn = DriverManager.getConnection(url, userName, passWord);

		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return conn;
	}

	public static void closeConnection(Connection con, Statement stmt,
			ResultSet rs) {
		try {
			if (rs != null)
				rs.close();
			rs = null;
		} catch (Exception ex) {

		}
		try {
			if (stmt != null)
				stmt.close();
			stmt = null;
		} catch (Exception e) {

		}

		try {
			if (con != null)
				con.close();
			con = null;
		} catch (Exception e) {

		}
	}

	public static void closeConnection(Connection con, PreparedStatement pstmt,
			ResultSet rs) {
		try {
			if (rs != null)
				rs.close();
			rs = null;
		} catch (Exception ex) {

		}
		try {
			if (pstmt != null)
				pstmt.close();
			pstmt = null;
		} catch (Exception e) {

		}

		try {
			if (con != null)
				con.close();
			con = null;
		} catch (Exception e) {

		}
	}

}
